package com.platform.user.center.portal.service.impl;

import com.platform.user.center.portal.dao.BaseMapper;
import com.platform.user.center.portal.service.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.io.Serializable;
import java.util.List;

/**
 * Created by churcy on 2017/2/16.
 */
@Transactional(readOnly = true)
@Service
public class BaseServiceImpl<T, PK extends Serializable> implements BaseService<T, PK> {

    @Autowired
    private BaseMapper<T> baseMapper;

    @Override
    public T get(PK id) {
        return baseMapper.selectByPrimaryKey(id);
    }

    @Override
    public List<T> getAll() {
        return baseMapper.selectAll();
    }

    @Override
    @Transactional
    public void save(T entity) {
        baseMapper.insert(entity);
    }

    @Override
    @Transactional
    public void update(T entity) {
        baseMapper.updateByPrimaryKey(entity);
    }

    @Override
    @Transactional
    public void delete(PK id) {
        baseMapper.deleteByPrimaryKey(id);
    }

}

